﻿using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;

using SRM.Core.Models;

using System.Security.Principal;
using System.Threading.Tasks;

namespace SRM.WebSite.ViewComponents
{
    public class IdentityPostViewComponent : ViewComponent
    {
        private readonly UserManager<ApplicationUser> _userManager;
        public IdentityPostViewComponent(UserManager<ApplicationUser> userManager)
        {
            _userManager = userManager;
        }

        public IViewComponentResult Invoke()
        {
            var user = _userManager.FindByNameAsync(User.Identity.Name)?.Result;
            string identity = string.IsNullOrEmpty(user?.SupplierName) ? "管理员" : "供应商";

            return View("IdentityPostRazor", identity);
        }
    }
}
